<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/html/js/axios.min.js"></script>
    <script src="/html/js/ajax.js"></script>
    <script>
        function changeCode() {
            getObject("codeImg").src = "/checkCode?" + Math.random();
        }

        async function add() {
            let inf = await ajaxGet("/session/add", {
                name: getObject("userName").value,
                userCode: getObject("code").value
            });
            if (inf == "ok") {
                location.href = "/html/index.html";
            } else if (inf == "codeError") {
                getObject("codeDiv").innerHTML = "验证错误";
            } else {
                alert("添加失败");
            }
        }
    </script>
</head>
<body>
姓名:<input type="text" id="userName"><br>
验证码:<img src="/checkCode" id="codeImg">
<a href="javascript:changeCode()">看不清楚，换一张</a><br>
请输入验证码:<input type="text" id="code">
<div id="codeDiv" style="color: red;font-size:12px;"></div>
<input type="button" value="添加" onclick="add()">
</body>
</html>